/**
 * Project Name:fire-industry-DM-center
 * File Name:ConverterArea.java
 * Package Name:com.firestone.converters.area
 * Date:2018年4月20日上午9:32:46
 *
*/

package com.firestone.converters.area;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.baomidou.mybatisplus.plugins.Page;
import com.firestone.bean.dto.area.AreaDTO;
import com.firestone.bean.dto.resource.ResourceListDTO;
import com.firestone.bean.vo.BaseListVO;
import com.firestone.bean.vo.area.AreaVO;
import com.firestone.bean.vo.resource.ResourceVO;
import com.firestone.common.tool.DateUtils;
import com.firestone.core.constants.ConstantMapKey;

/**
 * @Description: TODO(区域视图转化器)
 * @author CAIYJ
 * @date 2018年4月20日 上午9:32:46
 */
public final class ConverterArea {
    
    /**
     * @Description: TODO(项目列表视图转换)
     * @param page
     * @return
     * @author CAIYJ
     * @param <T>
     * @date 2018年3月30日 下午1:57:24
     * @lastModifier CAIYJ
     */
    public static final BaseListVO<AreaVO> convertListVO(
            Page<AreaDTO> page) {
        BaseListVO<AreaVO> vo = new BaseListVO<AreaVO>();
        if (page != null) {
            if (page.getRecords() != null && page.getRecords().size() > 0) {
                List<AreaVO> list = new ArrayList<>();
                for (AreaDTO resource : page.getRecords()) {
                    AreaVO areaVO = new AreaVO();
                    BeanUtils.copyProperties(resource, areaVO);
                    if (resource.getCreateTime() != null) {
                        areaVO.setCreateTime(DateUtils
                                .getTimeStampStr(resource.getCreateTime()));
                    }
                    if (resource.getUpdateTime() != null) {
                        areaVO.setUpdateTime(DateUtils
                                .getTimeStampStr(resource.getUpdateTime()));
                    }
                    areaVO.setIsDelete(ConstantMapKey.IS_DELETE
                            .get(resource.getIsDelete()));
                    list.add(areaVO);
                }
                vo.setList(list);
            }
            vo.setCount(page.getTotal());
        }
        return vo;
    }
}
